//
//  SearchMoreTopicsViewController.m
//  miaopai
//
//  Created by duyifang on 15/11/20.
//  Copyright © 2015年 Crow Zhang. All rights reserved.
//

#import "SearchMoreTopicsViewController.h"
#import "TopicDetailViewController.h"
#import "SearchTopicModel.h"
@interface SearchMoreTopicsViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, retain) UITableView *tableView;

@end

@implementation SearchMoreTopicsViewController

- (void)dealloc
{
    [_tableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"话题";
    // Do any additional setup after loading the view.
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height + 48) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_tableView];
    [_tableView.tableFooterView release];
    [_tableView release];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _topicsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
    cell.textLabel.text = [NSString stringWithFormat:@"%@",[[_topicsArray objectAtIndex:indexPath.row] name]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    TopicDetailViewController *topicDetailViewController = [[TopicDetailViewController alloc] init];
    SearchTopicModel *searchTopicModel = [_topicsArray objectAtIndex:indexPath.row];
    topicDetailViewController.stpid = searchTopicModel.stpid;
    topicDetailViewController.topicName = searchTopicModel.name;
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"";
    self.navigationItem.backBarButtonItem = backItem;
    [backItem release];

    [self.navigationController pushViewController:topicDetailViewController animated:YES];
    [topicDetailViewController release];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
